//
//  MYTransferredoutViewController.m
//  投融保
//
//  Created by 523 on 14-1-10.
//  Copyright (c) 2014年 木叶科技. All rights reserved.
//

#import "MYTransferredoutVC.h"
#import "MYWebService.h"
#import "MYRecommendViewController.h"

@interface MYTransferredoutVC ()

@end

@implementation MYTransferredoutVC
@synthesize dictHuaChu;

extern NSString *key;
extern NSString *appKey;
extern NSString *moneyhuachu;//划出金额
extern NSDictionary *userInformation;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard)];
    self.bgScrollView.contentSize=CGSizeMake(320, SCREEN_HEIGHT+100);
    [self.bgScrollView addGestureRecognizer:tapGesture];
    
    self.lblUserName.text=[userInformation valueForKey:@"realName"];
    
    self.bankImage.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[userInformation valueForKey:@"banklog"]]]];
    
    
    self.lblCardNo.text=[userInformation valueForKey:@"bankCardNo"];
    self.txtPassword.leftView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 44)];
    [self.txtPassword setLeftViewMode:UITextFieldViewModeAlways];
    
    
    self.lblAmount.text=[NSString stringWithFormat:@"%@ 元",moneyhuachu];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnHuachu:(UIButton *)sender {
    
    if([self.txtPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length>0){
        //    NSString *strWithdrawaslService=@"service=WithdrawaslService&amount=500&payPassword=123qwe";
        NSString *strWithdrawaslService=[NSString stringWithFormat:@"service=withdrawaslService&amount=%@&payPassword=%@",moneyhuachu,self.txtPassword.text];
        
        MBProgressHUD *mbHud = [[MBProgressHUD alloc] initWithView:self.view];
        
        mbHud.labelText = @"正在加载";
        
        [self.view addSubview:mbHud];
        
        [mbHud showAnimated:YES whileExecutingBlock:^{
            
            //z菊花转动的时候 开始加载数据
            dictHuaChu= [NSDictionary dictionaryWithDictionary:[[MYWebService new] getDataSynWithKey:key encryptedString:strWithdrawaslService appKey:appKey]];
        } completionBlock:^{
            //执行加载数据完成后的操作。
            if ([[dictHuaChu valueForKey:@"code"] intValue]==0) {
                NSString *message=[dictHuaChu objectForKey:@"message"];
                NSString *cancel=@"确定";
                ALERTVIEW(message, cancel);
            }else
            {
                [self transferredResultWithCode:dictHuaChu];
            }
        }];
    }
}

- (IBAction)btnReturn:(UIButton *)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (IBAction)closeKeyboard:(UITextField *)sender {
    [self.bgScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    [self.view endEditing:YES];
}

- (void)closeKeyboard
{
    [self.bgScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    [self.view endEditing:YES];
}

//划出成功后提示
- (void)transferredResultWithCode:(NSDictionary *)dictResult
{
    [self.bgScrollView removeFromSuperview];
    NSString *str1,*str2,*str3,*str4;
    if ([[dictResult objectForKey:@"code"] intValue]==1) {
        str1=@"划出成功";
        str2=@"继续划入";
        str3=[dictResult objectForKey:@"message"];
        str4=@"happyface";
    }else{
        str1=@"划出失败";
        str2=@"重试";
        str3=[dictResult objectForKey:@"message"];
        str4=@"Failed";
    }
    self.lblTitle.text=str1;
    Y_=0;
    if (IOS_VERSION>=7) {
        Y_=20;
    }
    UIView *viewTransferredscceuss=[[UIView alloc] initWithFrame:CGRectMake(0, 104+Y_, SCREEN_WIDTH, SCREEN_HEIGHT-Y_)];
    [viewTransferredscceuss setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:viewTransferredscceuss];
    
    
    UIImageView *imageFace=[[UIImageView alloc] initWithFrame:CGRectMake(240, 200, 60, 60)];
    imageFace.image=[UIImage imageNamed:str4];
    [viewTransferredscceuss addSubview:imageFace];
    
    UILabel *lblResult=[[UILabel alloc] initWithFrame:CGRectMake(320, 215, 200, 30)];
    lblResult.text=str3;
    lblResult.textColor=UIColorFromRGB(0xb70100);
    lblResult.textAlignment=NSTextAlignmentCenter;
    lblResult.backgroundColor=[UIColor clearColor];
    lblResult.font=[UIFont systemFontOfSize:24];
    [viewTransferredscceuss addSubview:lblResult];
    
    //继续划入
    UIButton *btnReTrans=[[UIButton alloc] initWithFrame:CGRectMake(54, 350, 300, 88)];
    [btnReTrans setBackgroundImage:[UIImage imageNamed:@"login_bg"] forState:UIControlStateNormal];
    [btnReTrans setTitle:str2 forState:UIControlStateNormal];
    [btnReTrans setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnReTrans.titleLabel setFont:[UIFont systemFontOfSize:26]];
    [btnReTrans addTarget:self action:@selector(btnReturn:) forControlEvents:UIControlEventTouchUpInside];
    [viewTransferredscceuss addSubview:btnReTrans];
    //返回首页
    UIButton *btnReturnHomepage=[[UIButton alloc] initWithFrame:CGRectMake(414, 350, 300, 88)];
    [btnReturnHomepage setBackgroundImage:[UIImage imageNamed:@"register_bg"] forState:UIControlStateNormal];
    [btnReturnHomepage setTitle:@"返回首页" forState:UIControlStateNormal];
    [btnReturnHomepage setTitleColor:UIColorFromRGB(0xb70100) forState:UIControlStateNormal];
    [btnReturnHomepage.titleLabel setFont:[UIFont systemFontOfSize:26]];
    [btnReturnHomepage addTarget:self action:@selector(btnReturnHomepageAction) forControlEvents:UIControlEventTouchUpInside];
    [viewTransferredscceuss addSubview:btnReturnHomepage];
}



- (void)btnReturnHomepageAction
{
    [self presentViewController:[MYRecommendViewController new] animated:NO completion:nil];
}

#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}
@end
